package top.zaixia.game.deployment.config;

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.redis.connection.RedisConnectionFactory
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer

@Configuration
class RedisConfig {
	@Bean
	fun redisTemplate(factory: RedisConnectionFactory): RedisTemplate<String, Any> =
		RedisTemplate<String, Any>().apply {
			connectionFactory = factory
			
			keySerializer = StringRedisSerializer()
			hashKeySerializer = StringRedisSerializer()
			
			valueSerializer = GenericJackson2JsonRedisSerializer()
			hashValueSerializer = GenericJackson2JsonRedisSerializer()
		}.apply {
			afterPropertiesSet()
		}
}
